package com.rzhd.coursepatriarch.common.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by CL on 2018/1/3.
 * 禁止左右滑动viewpage
 */

public class NoScrollViewPager extends ViewPager {
    private boolean pageScroll = false;
    private boolean pageScrollAnimal = false;

    public NoScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public NoScrollViewPager(Context context) {
        super(context);
    }


    @Override
    public void scrollTo(int x, int y) {
        super.scrollTo(x, y);
    }

    //禁止页面滑动
    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        /* return false;//super.onTouchEvent(arg0); */
        if (pageScroll)
            return super.onTouchEvent(arg0);
        else
            return pageScroll;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if (pageScroll)
            return super.onInterceptTouchEvent(arg0);
        else
            return pageScroll;
    }

    //去除页面切换时的滑动翻页效果
    @Override
    public void setCurrentItem(int item) {
        if (pageScrollAnimal)
            super.setCurrentItem(item);
        else
            super.setCurrentItem(item, false);
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        super.setCurrentItem(item, smoothScroll);
    }

    public void setPageScroll(boolean pageScroll) {
        this.pageScroll = pageScroll;
    }

    public void setPageScrollAnimal(boolean pageScrollAnimal) {
        this.pageScrollAnimal = pageScrollAnimal;
    }
}